﻿namespace MyTRCP.Common
{
    public abstract class BitWalkableObj
    {
        public BitWalkableObj() { }
        public BitWalkableObj(byte[] data) : this(data, 0, data.Length) { }
        public BitWalkableObj(byte[] data, int pos, int len)
        {
            ReadFromBytes(data, pos, len);
        }
        public abstract BitWalker WriteToBitWalker(BitWalker bw);
        public abstract BitWalker ReadFromBitWalker(BitWalker bw);

        public byte[] WriteToBytes()
        {
            return WriteToBitWalker(new BitWalker()).ToBytes();
        }
        public void ReadFromBytes(byte[] data, int pos, int len)
        {
            ReadFromBitWalker(new BitWalker(data, pos, len));
        }
    }
}